package com.guowen.myaccount.adapter;

import android.content.Context;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.guowen.myaccount.R;
import com.guowen.myaccount.db.AccountBean;

import java.util.List;

public class AccountAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<AccountBean> mDatas;

    public AccountAdapter(Context context, List<AccountBean> mDatas){
        this.context = context;
        this.mDatas = mDatas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.item_main_lv,parent,false);
        ViewHolder holder = new ViewHolder(convertView);
        AccountBean accountBean = mDatas.get(position);
        holder.typeIv.setImageResource(accountBean.getsImageId());
        holder.typeTv.setText(accountBean.getTypename());
        holder.beizhuTv.setText(accountBean.getBeizhu());
        holder.moneyTv.setText(accountBean.getMoney()+"");
        holder.accountTv.setText(accountBean.getAccount());
        holder.timeTv.setText(accountBean.getTime());
        if (accountBean.getWeight() != -1){
            holder.weightTv.setText("喜好度："+accountBean.getWeight());
        }else {
            holder.weightTv.setText("");
        }
        return convertView;
    }

    class ViewHolder{

        private ImageView typeIv;
        private TextView typeTv, beizhuTv, moneyTv, accountTv, timeTv, weightTv;

        public ViewHolder(View view){
            typeIv = view.findViewById(R.id.item_main_lv_iv);
            typeTv = view.findViewById(R.id.item_main_lv_title);
            beizhuTv = view.findViewById(R.id.item_main_lv_beizhu);
            moneyTv = view.findViewById(R.id.item_main_lv_money);
            accountTv = view.findViewById(R.id.item_main_lv_account);
            timeTv = view.findViewById(R.id.item_main_lv_time);
            weightTv = view.findViewById(R.id.item_main_lv_weight);
        }

    }
}
